<template>
	<view class="container">
		<TopBtn :title="'编辑资料'"></TopBtn>
		<view class="info">
			<view class="currency_card">
				<view class="currency_title flex-sp-center">
					擅长
				</view>
				<view class="mt_30">
					<textArea v-model="baseFormData.proficient" :inputNane="baseFormData.proficient" class="mb_30" :maxNum="200"></textArea>
				</view>
			</view>
			<view class="currency_card">
				<view class="currency_title flex-sp-center">
					医生简介
				</view>
				<view class="mt_30">
					<textArea v-model="baseFormData.introduction" :inputNane="baseFormData.introduction" class="mb_30" :maxNum="500"></textArea>
				</view>
			</view>
			<view class="btn" @click="updateDoctorInfo()">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getDoctorInfo,
		updateDoctorInfo
	} from '@/api/user'
	export default {
		data() {
			return {
				baseFormData: {},
				type: [{
					text: '投诉',
					value: 0
				}, {
					text: '建议',
					value: 1
				}],
				filePathsList: [],
				Url: "app-api/infra/file/uploadPhotos",
			};
		},
		onLoad() {
			this.getDoctorInfo()
		},
		methods: {
			updateDoctorInfo(){
				updateDoctorInfo(this.baseFormData).then(res => {
					this.baseFormData=res.data
					this.getDoctorInfo()
					uni.showToast({
						title: '修改成功',
						icon: 'none',
						duration: 2000,
						mask:true
					})
					setTimeout(() => {
						//需要定时执行的代码
						uni.navigateBack({
							delta: 1, //返回层数，2则上上页
						})
					}, 2000)
				})
			},
			getDoctorInfo() {
				getDoctorInfo().then(res => {
					this.baseFormData=res.data
				})
			},
			handleDelete(err) { // 删除图片
				const num = this.filePathsList.findIndex(v => v.url === err.tempFilePath);
				this.filePathsList.splice(num, 1);
			},
			select(e) {
				let that = this
				uni.showLoading({
					title: "上传中"
				});
				const tempFilePaths = e.tempFilePaths;
				for (var i = 0; i < tempFilePaths.length; i++) {
					const tempFile = e.tempFiles[i];
					uni.uploadFile({
						url: this.Url,
						header: {
							'token': uni.getStorageSync('token'),
						},
						filePath: tempFilePaths[i],
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let data = {}
							if (JSON.parse(uploadFileRes.data).code == 0) {
								data.url = JSON.parse(uploadFileRes.data).data
								this.filePathsList.push(data)
							} else {
								data.url = JSON.parse(uploadFileRes.data).msg
								this.filePathsList.push(data)
								this.filePathsList.pop()
								uni.showToast({
									title: JSON.parse(uploadFileRes.data).msg,
									icon: "none",
									duration: 2000
								});
							}
						},
						fail: () => {
							uni.hideLoading();
							uni.showToast("上传失败，请联系开发！")
						},
						complete: function() {
							uni.hideLoading();
						}
					});
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.btn{
		width: 649rpx;
		height: 100rpx;
		background: #3B6CFE;
		border-radius: 50rpx;
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 100rpx;
		margin: 200rpx auto 0;
	}
	.container {
		padding-top: 158rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		box-sizing: border-box;
		min-height: 100vh;

		.info {
			flex: 1;
			width: 750rpx;
			background: #FFFFFF;
			border-radius: 52rpx 52rpx 0 0;
			padding: 30rpx ;
			box-sizing: border-box;

			.text {
				font-weight: 500;
				font-size: 24rpx;
				color: #666666
			}

			/deep/.is-input-border {
				border: none;
			}

			/deep/.uni-easyinput__content-input {
				text-align: right;
				padding-right: 10rpx;
			}

			/deep/ .uni-forms-item__label {
				font-weight: bold;
				font-size: 30rpx;
				color: #333333;
			}

			/deep/ .uni-forms-item {
				margin-bottom: 0rpx;
			}

			/deep/.uni-forms-item__content {
				display: flex;
				align-items: center;
				justify-content: right;
			}

			/deep/.checklist-group {
				justify-content: right;
			}
		}
	}
</style>